package la.bbs558.util;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.symmetric.AES;

/**
 * @Classname AESUtils
 * @Description TODO
 * @Date 2023/12/6 09:53
 * @Created by weihanmin
 */
public class AESUtils {

    public static final String SECRET_KEY = "0123456789ABHAEQ";

    public static String encrypt(String content,String salt){
        AES aes = new AES("CBC", "PKCS7Padding",
                // 密钥，可以自定义
                SECRET_KEY.getBytes(),
                // iv加盐，按照实际需求添加
                salt.getBytes());
        return aes.encryptHex(content);
    }

    public static String decrypt(String content,String salt){
        AES aes = new AES("CBC", "PKCS7Padding",
                // 密钥，可以自定义
                SECRET_KEY.getBytes(),
                // iv加盐，按照实际需求添加
                salt.getBytes());
        return aes.decryptStr(content);
    }

    public static void main(String[] args) {
        String content = "123";
        String slat = RandomUtil.randomString(16);
        String encrypt = encrypt(content,slat);
        String decrypt = decrypt(encrypt,slat);
        System.out.println("encrypt = " + encrypt);
        System.out.println("decrypt = " + decrypt);
    }
}
